package com.byedu.course;

import com.byedu.domain.course.GuideInforDO;
import com.byedu.domain.course.JobInforDO;
import com.byedu.domain.course.vo.JobInforVO;
import com.byedu.mapper.course.JobInforMapper;
import com.byedu.model.enums.CityTypeEnum;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Luo on 2017-09-21.
 */
@Service
public class JobInforService {

    @Autowired
    JobInforMapper jobInforMapper;

    public List<JobInforVO> getJobInforList(JobInforDO jobInforDO) {

        return convertDoListToVoList(jobInforMapper.getJobInforList(jobInforDO));
    }

    public JobInforDO getJobInforbyId(int id) {

        return jobInforMapper.getJobInforbyId(id);
    }
    public List<JobInforVO> convertDoListToVoList(List<JobInforDO> jobInforDOList) {
        List<JobInforVO> jobInforVOList = new ArrayList<JobInforVO>();
        if (CollectionUtils.isNotEmpty(jobInforDOList)) {

            for (JobInforDO jobInforDO : jobInforDOList) {
                JobInforVO jobInforVO = new JobInforVO(jobInforDO);
                jobInforVOList.add(jobInforVO);
            }

            return jobInforVOList;
        }
        return jobInforVOList;
    }

    public List<String> getJobsCity() {

            List<String> list = new ArrayList<String>();
            for (CityTypeEnum cityTypeEnum : CityTypeEnum.values()) {
                String cityString = cityTypeEnum.getValue();
                list.add(cityString);
            }

            return list;
    }

    public List<JobInforVO> getJobInforLists() {

        return convertDoListToVoList(jobInforMapper.getJobInforLists());
    }

    public int saveJobInfor(JobInforDO jobInforDO){
        return jobInforMapper.saveJobInfor(jobInforDO);
    }

    public int updateJobInfor(JobInforDO jobInforDO){
        return jobInforMapper.updateJobInfor(jobInforDO);
    }
}
